package com.tywj.lib.route

import android.content.Intent
import android.os.Parcelable
import java.io.Serializable

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/8
 *     desc   : 获取Activity路由参数
 *     version: 1.0.0
 * </pre>
 */
internal class ActivityRouteParam(private val intent: Intent) : IRouteParam {

    override fun getInt(key: String, defaultValue: Int): Int {
        return intent.getIntExtra(key, defaultValue)
    }

    override fun getLong(key: String, defaultValue: Long): Long {
        return intent.getLongExtra(key, defaultValue)
    }

    override fun getFloat(key: String, defaultValue: Float): Float {
        return intent.getFloatExtra(key, defaultValue)
    }

    override fun getDouble(key: String, defaultValue: Double): Double {
        return intent.getDoubleExtra(key, defaultValue)
    }

    override fun getBoolean(key: String, defaultValue: Boolean): Boolean {
        return intent.getBooleanExtra(key, defaultValue)
    }

    override fun getString(key: String, defaultValue: String): String {
        return intent.getStringExtra(key) ?: defaultValue
    }

    @Suppress("UNCHECKED_CAST")
    override fun <T : Serializable> getSerializable(key: String): T? {
        return intent.getSerializableExtra(key) as T?
    }

    override fun <T : Parcelable> getParcelable(key: String): T? {
        return intent.getParcelableExtra(key) as T?
    }

    override fun <T : Parcelable> getParcelableArrayList(key: String): ArrayList<T>? {
        return intent.getParcelableArrayListExtra(key)
    }
}